import useApiFetch from '~/hooks/useApiFetch';

export interface LoginRes {
  token: string;
  refreshToken: string;
}
export interface LoginParams {
  userAccount: string;
  password: string;
}

export enum RoleType {
  NORMAL = 'NORMAL',
  VIP = 'VIP',
  SVIP = 'SVIP',
}

export interface UserInfo {
  username: string;
  email: string;
  createTime: string;
  updateTime: string;
  points: number;
  role: RoleType;
  vipEndTime?: string;
  vipStartTime?: string;
  energy: number; // 能量值总数
}
export interface RegisterParams {
  username: string;
  password: string;
  email?: string;
}
export interface RegisterRes {
  token: string;
  refreshToken: string;
  userInfo: UserInfo;
}

export const queryLogin = (body: LoginParams) => {
  return useApiFetch<ResOptions<LoginRes>>('/user/login', {
    method: 'POST',
    body,
  });
};

export const queryRegister = (body: RegisterParams) => {
  return useApiFetch<ResOptions<RegisterRes>>('/user/register', {
    method: 'POST',
    body,
  });
};

export const queryUserInfo = () => {
  return useApiFetch<ResOptions<UserInfo>>('/user/userInfo', {
    method: 'GET',
  });
};

export const queryGetPoints = () => {
  return useApiFetch<ResOptions<number>>('/user/getPoints', {
    method: 'GET',
  });
};
